package com.shtel.paas.monitorcenter.config.management.collection.config.controller;

import java.util.List;
import java.util.Map;

import com.shtel.paas.monitorcenter.config.management.collection.config.vo.MonitoringIndexConfigurationVO;
import com.shtel.paas.monitorcenter.config.management.collection.config.vo.MonitoringIndexVO;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.shtel.paas.monitorcenter.config.management.collection.config.entity.CollectionConfigEntity;
import com.shtel.paas.monitorcenter.config.management.collection.config.entity.UpdateConfigurationCollectionEntity;
import com.shtel.paas.monitorcenter.config.management.collection.config.service.CollectionConfigService;
import com.shtel.paas.monitorcenter.config.management.collection.config.vo.CollectionConfigVo;
import com.shtel.paas.monitorcenter.util.Page;

/**
 * 
 * @author zhaochuan.zhong
 *
 */
// @EnablePaasMybatis
@MapperScan("com.shtel.paas.monitorcenter.config.management.collection.config.mapper")
// mybatis存储库类的包路径
@RestController
public class CollectionConfigController {

	@Autowired
	private CollectionConfigService collectionConfigService;

	/**
	 * 获取指标配置信息。
	 */
	@GetMapping("/selectConfiguationCollectionInfo")
	public Page<CollectionConfigVo> selectConfiguationCollectionInfo(
			@RequestParam("monitorIndex") String monitorIndex,
			@RequestParam("IndexKpi") String IndexKpi,
			@RequestParam("page") Integer page,
			@RequestParam("size") Integer pageSize) {
		CollectionConfigEntity parameter = new CollectionConfigEntity();

		parameter.setMonitorIndex(monitorIndex);
		parameter.setIndexKpi(IndexKpi);
		parameter.setPage(page);
		parameter.setSize(pageSize);
		Page<CollectionConfigVo> pageContent = collectionConfigService.selectCollectionConfigInfo(parameter);
		return pageContent;
	}

	/**
	 * 更新指标配置信息。
	 */
	@GetMapping("/updateCollectionConfigInfo")
	public Integer updateCollectionConfigInfo(@RequestParam("id") Integer id,@RequestParam("dataAcquisitionFrequency") String dataAcquisitionFrequency,@RequestParam("monitorIndex") String monitorIndex, @RequestParam("indexKpi") String indexKpi,
											  @RequestParam("times") String times,@RequestParam("minutes") String minutes) {
		UpdateConfigurationCollectionEntity paramter =  new UpdateConfigurationCollectionEntity();
		paramter.setId(id);
		paramter.setDataAcquisitionFrequency("0 0/"+dataAcquisitionFrequency+" * * * ? *");
		paramter.setMonitorIndex(monitorIndex);
		paramter.setIndexKpi(indexKpi);
		paramter.setTimes(times);
		paramter.setMinutes(minutes);
		Integer resultCount = collectionConfigService.updateCollectionConfigInfo(paramter);
		return resultCount;
	}

	/**
	 * 获取主机刷新信息。
	 */
	@GetMapping("/selectConfiguationCollectionTab2Info")
	public Page<CollectionConfigVo> selectConfiguationCollectionTab2Info(
			@RequestParam("hostIp") String hostIp,
			@RequestParam("hostName") String hostName,
			@RequestParam("page") Integer page,
			@RequestParam("size") Integer pageSize) {
		CollectionConfigEntity parameter = new CollectionConfigEntity();

		parameter.setHostIp(hostIp);
		parameter.setHostName(hostName);
		parameter.setPage(page);
		parameter.setSize(pageSize);
		Page<CollectionConfigVo> pageContent = collectionConfigService.selectCollectionConfigTab2Info(parameter);
		return pageContent;
	}


	/**
	 * 更新主机刷新配置信息。
	 */
	@GetMapping("/updateCollectionConfigTab2Info")
	public Integer updateCollectionConfigTab2Info(@RequestParam("id") Integer id,
												  @RequestParam("hostIp") String hostIp,
												  @RequestParam("hostName") String hostName,
												  @RequestParam("refreshTime") String refreshTime,@RequestParam("sytemParameterId") String sytemParameterId) {
		UpdateConfigurationCollectionEntity paramter =  new UpdateConfigurationCollectionEntity();
		paramter.setId(id);
		paramter.setRefreshTime(refreshTime);
		paramter.setSytemParameterId(Integer.parseInt(sytemParameterId));
		Integer resultCount = collectionConfigService.updateCollectionConfigTab2Info(paramter);
		return resultCount;
	}

	/**
	 * 下拉框取值。
	 */
	@GetMapping("/getListOptionValue")
	public Map<String, Object>  getSelectOptionValue() {

		Map<String, Object> result = collectionConfigService.selectOptionValue();
		return result;
	}
	/**
	 * 查询数据采集频率
	 * creat by:zhangyy
	 * @param
	 * @return String
	 */
	@GetMapping("/queryDataAcquisitionFrequency")
	public String queryDataAcquisitionFrequency() {

		return collectionConfigService.queryDataAcquisitionFrequency();
	}

	/**
	 * 查询监控指标ztree根目录
	 * creat by:zhangyy
	 * @param
	 * @return list
	 */
	@GetMapping("/selectMonitoringIndex")
	public List<MonitoringIndexConfigurationVO> selectMonitoringIndex() {
		return collectionConfigService.selectMonitoringIndex();
	}

	/**
	 * 查询监控指标ztree子节点
	 * creat by:zhangyy
	 * @param
	 * @return list
	 */
	@GetMapping("/asyncGetKPITreeData")
	public List<MonitoringIndexVO> asyncGetKPITreeData(@RequestParam("id") String id) {
		return collectionConfigService.asyncGetKPITreeData(id);
	}

	/**
	 * 修改数据采集频率
	 * creat by:zhangyy
	 * @param
	 * @return Integer
	 */
	@GetMapping("/updataDataAcquisitionFrequency")
	public Integer  updataDataAcquisitionFrequency(@RequestParam("dataAcquisitionFrequency") String dataAcquisitionFrequency) {
		return collectionConfigService.updataDataAcquisitionFrequency(dataAcquisitionFrequency);
	}

	/**
	 * 批量修改times AND minutes
	 * creat by:zhangyy
	 * @param
	 * @return reult
	 */
	@GetMapping("/updataTimesANDMinutes")
	public Integer updataTimesANDMinutes(
			@RequestParam("id") Integer id,
			@RequestParam("times") String times,
			@RequestParam("minutes") String minutes) {
		UpdateConfigurationCollectionEntity paramter =  new UpdateConfigurationCollectionEntity();
		paramter.setId(id);
		paramter.setTimes(times);
		paramter.setMinutes(minutes);
		Integer resultCount = collectionConfigService.updataTimesANDMinutes(paramter);
		return resultCount;
	}
}
